<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <link rel="stylesheet" href="../../lib/jq-module/zyupload/zyupload-1.0.0.min.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">

    <div class="layui-form-item">
        <label class="layui-form-label required">房源名称：</label>
        <select name="f_id" id="fids" lay-verify="required">

        </select>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">租客：</label>
        <select name="l_id" id="lids" lay-verify="required">

        </select>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">合同：</label>
        <select name="c_id" id="hids" lay-verify="required">

        </select>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">打扫：</label>
        <select name="h_id" id="cids" lay-verify="required">

        </select>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">新增课程</button>
        </div>
    </div>
</div>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../lib/jq-module/zyupload/zyupload-1.0.0.min.js" charset="utf-8"></script>
<script>
    var form,$;

    layui.use(['form'], function () {
        form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        loadGids();
        sellLessee();
        sellContract();
        sellClear();

        //监听提交，实现数据新增
        form.on('submit(saveBtn)', function (data) {
            //请求接口  Ajax
            var d=data.field;
            console.log(d)
            $.post("/api/rentingdto/save.do",d,function (res){
                if(res.code==200){
                    layer.msg("添加成功！");
                    // 关闭弹出层
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                }else {
                    layer.msg("亲，新增学科失败！");
                }
            })
            return false;
        });

    });

    //加载户主信息
    function loadGids(){
        //请求接口  Ajax
        // 租房
        $.get("/api/house/allhouse.do",(res)=>{
            if(res.code==200){
                console.log(res.data)
                $("#fids").html("");
                //遍历
                for(var i in res.data){
                    $("#fids").append("<option value='"+res.data[i].id+"'>"+"房子类型："+res.data[i].houseType+"，"+"房子地址："+res.data[i].houseSite+"</option>");
                }
                form.render('select'); //渲染 select 选择框
            }
        })
    }
    function sellLessee(){
        //请求接口  Ajax
        // 租户
        $.get("/api/lessee/alldto.do",(res)=>{
            if(res.code==200){
                $("#lids").html("");
                //遍历
                for(var i in res.data){
                    $("#lids").append("<option value='"+res.data[i].id+"'>"+"租户名："+res.data[i].name+"，"+"性别："+res.data[i].sex+"，"+"手机号："+res.data[i].phone+"，"+"身份证号："+res.data[i].id_number+"</option>");
                }
                form.render('select'); //渲染 select 选择框
            }
        })
    }
    function sellClear(){
        //请求接口  Ajax
        // 合同
        $.get("/api/contract/alldto.do",(res)=>{
            console.log(res.data)
            if(res.code==200){
                $("#hids").html("");
                //遍历
                for(var i in res.data){
                    $("#hids").append("<option value='"+res.data[i].id+"'>"+"合同名："+res.data[i].contractName+"</option>");
                }
                form.render('select'); //渲染 select 选择框
            }
        })
    }
    function sellContract(){
        //请求接口  Ajax
        // 清洁
        $.get("/api/clean/all.do",(res)=>{
            console.log(res.data)
            if(res.code==200){
                $("#cids").html("");
                //遍历
                for(var i in res.data){
                    $("#cids").append("<option value='"+res.data[i].id+"'>"+"房间打扫："+res.data[i].enat+"</option>");
                }
                form.render('select'); //渲染 select 选择框
            }
        })
    }

</script>
</body>
</html>